package com.zhijian.medical.controller;

import com.zhijian.BusinessException;
import com.zhijian.medical.entity.po.RoutinePatientException;
import com.zhijian.medical.enums.RoutinePathologySampleStepEnum;
import com.zhijian.medical.service.RoutinePatientExceptionService;
import com.zhijian.response.annotation.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Controller
@Api(tags = "常规病理-离体固定-样本异常")
public class RoutinePatientExceptionController {

    @Autowired
    RoutinePatientExceptionService routinePatientExceptionService;

    @Response
    @GetMapping("/routine/patient/exception/body/{patientId}")
    @ApiOperation("离体异常查询")
    public RoutinePatientException selectByCondition(@PathVariable("patientId") Long patientId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), patientId);
        return routinePatientExceptionService.readException(patientId, RoutinePathologySampleStepEnum.LT);
    }

    @Response
    @GetMapping("/routine/patient/exception/fixed/{patientId}")
    @ApiOperation("固定异常查询")
    public RoutinePatientException selectFixedByCondition(@PathVariable("patientId") Long patientId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), patientId);
        return routinePatientExceptionService.readException(patientId, RoutinePathologySampleStepEnum.GD);
    }

    @Response
    @PostMapping("/routine/patient/exception/body")
    @ApiOperation("新增离体异常")
    public RoutinePatientException addAndUpdateBody(@RequestBody RoutinePatientException routinePatientException) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), routinePatientException);
        if (routinePatientException.getPatientId() == null){
            throw new BusinessException(500, "确实必要patientId的参数！");
        }
        routinePatientException.setExType(RoutinePathologySampleStepEnum.LT.getCode());
        return routinePatientExceptionService.addAndUpdException(routinePatientException);
    }

    @Response
    @PostMapping("/routine/patient/exception/fixed")
    @ApiOperation("新增固定异常")
    public RoutinePatientException addAndUpdateFixed(@RequestBody RoutinePatientException routinePatientException) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), routinePatientException);
        if (routinePatientException.getPatientId() == null){
            throw new BusinessException(500, "确实必要patientId的参数！");
        }
        routinePatientException.setExType(RoutinePathologySampleStepEnum.GD.getCode());
        return routinePatientExceptionService.addAndUpdException(routinePatientException);
    }

    @Response
    @PutMapping("/routine/patient/exception/body")
    @ApiOperation("修改离体异常")
    public RoutinePatientException updateBody(@RequestBody RoutinePatientException routinePatientException) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), routinePatientException);
        if (routinePatientException.getPatientId() == null){
            throw new BusinessException(500, "确实必要patientId的参数！");
        }
        routinePatientException.setExType(RoutinePathologySampleStepEnum.LT.getCode());
        return routinePatientExceptionService.addAndUpdException(routinePatientException);
    }

    @Response
    @PutMapping("/routine/patient/exception/fixed")
    @ApiOperation("修改固定异常")
    public RoutinePatientException updateFixed(@RequestBody RoutinePatientException routinePatientException) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), routinePatientException);
        if (routinePatientException.getPatientId() == null){
            throw new BusinessException(500, "确实必要patientId的参数！");
        }
        routinePatientException.setExType(RoutinePathologySampleStepEnum.GD.getCode());
        return routinePatientExceptionService.addAndUpdException(routinePatientException);
    }
}
